/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.gov.cemaden.smp.controler;

import br.gov.cemaden.factory.DaoFactory;
import br.gov.cemaden.library.dao.smp.WhoSysDao;
import br.gov.cemaden.library.model.smp.WhoSys;
import java.io.Serializable;
import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 *
 * @author Simone Santos
 */
public class WhoBean implements Serializable {

    public WhoBean() {
    }

    public WhoSys getWhoSys() throws UnknownHostException {

        String computerName = InetAddress.getLocalHost().getHostName();
        String computerIp = InetAddress.getLocalHost().getHostAddress();

        WhoSysDao dao = new DaoFactory<WhoSysDao>(WhoSysDao.class).get();
        WhoSys whoHost = null;

        if (dao != null) {
            whoHost = dao.findByHostAddressAndHostName(computerIp, computerName);
            if (whoHost == null) {
                whoHost = new WhoSys();
                whoHost.setHostAddress(computerIp);
                whoHost.setHostName(computerName);
                dao.insert(whoHost);
            }
        }

        return whoHost;
    }

    public void show(WhoSys t) {
        System.out.println("HostName: " + t.getHostName());
        System.out.println("HostAddress: " + t.getHostAddress());
        System.out.println("--------------------------------\n");
    }
}
